package com.zhonghui.scm.controller;

import com.zhonghui.common.core.controller.BaseController;
import com.zhonghui.common.core.page.TableDataInfo;
import com.zhonghui.common.utils.poi.ExcelUtil;
import com.zhonghui.response.BaseResult;
import com.zhonghui.scm.domain.ScmSaleReturn;
import com.zhonghui.scm.service.IScmSaleReturnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 销售退货Controller
 * 
 * @author zhonghui
 * @date 2022-05-26
 */
@Api(tags="供应链SCM-销售管理-销售退货")
@RestController
@RequestMapping("/scm/return")
public class ScmSaleReturnController extends BaseController
{
    @Autowired
    private IScmSaleReturnService scmSaleReturnService;

    /**
     * 查询销售退货列表
     */
    @ApiOperation("销售管理-销售退货列表")
    @GetMapping("/list")
    public TableDataInfo<List<ScmSaleReturn>> getList(ScmSaleReturn scmSaleReturn)
    {
        startPage();
        List<ScmSaleReturn> list = scmSaleReturnService.getList(scmSaleReturn);
        return getDataTable(list);
    }

    /**
     * 导出销售退货列表
     */
    @ApiOperation("导出销售管理-销售退货列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmSaleReturn scmSaleReturn)
    {
        List<ScmSaleReturn> list = scmSaleReturnService.getList(scmSaleReturn);
        ExcelUtil<ScmSaleReturn> util = new ExcelUtil<ScmSaleReturn>(ScmSaleReturn.class);
        util.exportExcel(response, list, "销售退货数据");
    }

    /**
     * 获取销售退货详细信息
     */
    @ApiOperation("销售管理-销售退货详细信息")
    @GetMapping(value = "/{id}")
    public BaseResult<ScmSaleReturn> getById(@PathVariable("id") Long id)
    {
        return BaseResult.success(scmSaleReturnService.getById(id));
    }

    /**
     * 新增销售退货
     */
    @ApiOperation("新增销售管理-销售退货")
    @PostMapping
    public BaseResult<Integer> add(@RequestBody ScmSaleReturn scmSaleReturn)
    {
        return BaseResult.success(scmSaleReturnService.add(scmSaleReturn));
    }

    /**
     * 修改销售退货
     */
    @ApiOperation("修改销售管理-销售退货")
    @PutMapping
    public BaseResult<Integer> edit(@RequestBody ScmSaleReturn scmSaleReturn)
    {
        return BaseResult.success(scmSaleReturnService.edit(scmSaleReturn));
    }

    /**
     * 删除销售退货
     */
    @ApiOperation("删除销售管理-销售退货")
	@DeleteMapping("/{ids}")
    public BaseResult<Integer> remove(@PathVariable Long[] ids)
    {
        return BaseResult.success(scmSaleReturnService.del(ids));
    }
}
